<?php
class Zendvn_Controller_Action extends Zend_Controller_Action{
	
	//Zendvn_Template
	protected $_templateObj;
	
	//Param array
	public  $_arrParam;	
	
	//Zendvn_Languages
	protected $_langObj;
	
	//Site Config
	protected $_configObj;
	
	//Current controller
	protected $_currentController;
	
	//Main action
	protected $_mainAction;
	
	//Controller Session Namespace
	protected $_ssNamespace;
	
	//Info of system and user
	protected $_infoObj;
	
	public function init(){
		
		$this->_arrParam = $this->_request->getParams();
		
		//Path to Controller include folder
		$this->view->includeDir = '/' . $this->_arrParam['controller'] . '/includes';
		
		//Template Obj
		$this->_templateObj = new Zendvn_Template($this);
		
		$this->_infoObj = new Zendvn_System_Info();
		$this->view->infoObj = $this->_infoObj;
		//Language Obj
		$lang = $this->_infoObj->getLanguage('admin');
		$this->_langObj = new Zendvn_Languages($lang);	
		$this->view->sysLang = $this->_langObj->listLanguage();
			
		
		//Site Config Obj
		$this->_configObj = new Zendvn_Config();	
		$this->view->configObj = $this->_configObj;
		
		//Main action
		$this->_currentController = $this->_arrParam['module'] . '/' . $this->_arrParam['controller'];
		$this->_mainAction = $this->_currentController . '/index';
		
		//Controller Session Namespace
		$this->_ssNamespace = 'ss_' . md5($this->_arrParam['module'] 
									. '/' . $this->_arrParam['controller']);
		
		if($this->_arrParam['accessArea'] == 'admin' || $this->_arrParam['action'] == 'login'){
			$menu = new Zendvn_Menu();
			$menu->setGroup('admin');
			$this->view->objMenu = $menu;
			
		}
	}
	
	protected function setMeta($arrParam){
		if(!empty($arrParam)){
			foreach ($arrParam as $k => $v){
				switch ($v[0]){
				    case 'name':
				    	$this->view->headMeta()->appendName($v[1], $v[2]);
				    	break;
				    case 'property':
				    	$this->view->doctype('XHTML1_RDFA');
				    	$this->view->headMeta()->setProperty($v[1], $v[2]);
				    	break;
				    default:
				    	break;
				}
			}
		}
	}
	
	public function setTitle($title, $option = array()){
		$this->view->Title = $title;
		$this->view->headTitle($this->view->Title,true);
	
		if(!empty($option['keywords'])){
			$this->view->headMeta()->setName('keywords',$option['keywords']);
		}
		if(!empty($option['description'])){
			$this->view->headMeta()->setName('description',$option['description']);
		}
	}
}